The .NET framework class library provides methods for retrieving custom attributes. Sealing the attribute eliminates the search through the
inheritance hierarchy, and can improve performance.
This rule raises an issue when a public type inherits from System.Attribute
, is not abstract, and is not sealed.
Noncompliant code example
Public Class MyAttribute ' Noncompliant
Inherits Attribute
Public ReadOnly Property Name As String
Public Sub New(Name As String)
Me.Name = Name
End Sub
End Class
Compliant solution
Public NotInheritable Class MyAttribute
Inherits Attribute
Public ReadOnly Property Name As String
Public Sub New(Name As String)
Me.Name = Name
End Sub
End Class